/**
 * FileName: MyFilterConfig
 * Author:   xing.yang@vcg.com
 * Date:     2020/2/27 10:24
 * Description: 手动注入filter
 */
package com.vcg.vdam.config;

import com.vcg.vdam.aop.TestFilter;
import com.vcg.vdam.aop.TestFilter2;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MyFilterConfig implements DisposableBean {
//    @Value("${xxl.sso.server}")
//    private String xxlSsoServer;
//
//    @Value("${xxl.sso.logout.path}")
//    private String xxlSsoLogoutPath;
//
//    @Value("${xxl-sso.excluded.paths}")
//    private String xxlSsoExcludedPaths;
//
//    @Value("${xxl.sso.redis.address}")
//    private String xxlSsoRedisAddress;


    @Bean
    public FilterRegistrationBean xxlSsoFilterRegistration() {

        // xxl-sso, redis init 手动初始化redis
//        JedisUtil.init(xxlSsoRedisAddress);

        // xxl-sso, filter init
        FilterRegistrationBean registration = new FilterRegistrationBean();

        registration.setName("XxlSsoWebFilter");
        registration.setOrder(1);
        registration.addUrlPatterns("/*");
        registration.setFilter(new TestFilter());
//        registration.addInitParameter(Conf.SSO_SERVER, xxlSsoServer);
//        registration.addInitParameter(Conf.SSO_LOGOUT_PATH, xxlSsoLogoutPath);
//        registration.addInitParameter(Conf.SSO_EXCLUDED_PATHS, xxlSsoExcludedPaths);

        return registration;
    }

    @Bean
    public FilterRegistrationBean xxlSsoFilterRegistration2() {

        // xxl-sso, redis init 手动初始化redis
//        JedisUtil.init(xxlSsoRedisAddress);

        // xxl-sso, filter init
        FilterRegistrationBean registration = new FilterRegistrationBean();

        registration.setName("XxlSsoWebFilter2");
        registration.setOrder(2);
        registration.addUrlPatterns("/*");
        registration.setFilter(new TestFilter2());
//        registration.addInitParameter(Conf.SSO_SERVER, xxlSsoServer);
//        registration.addInitParameter(Conf.SSO_LOGOUT_PATH, xxlSsoLogoutPath);
//        registration.addInitParameter(Conf.SSO_EXCLUDED_PATHS, xxlSsoExcludedPaths);

        return registration;
    }

    @Override
    public void destroy() throws Exception {

        // xxl-sso, redis close
//        JedisUtil.close();
    }



}
